<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客户关系管理及报关单统计系统</title>
<!--#include file="lib/plugins.asp"-->
<!--#include file="lib/js-jquery-validate-lib.asp"-->
<!--#include file="lib/css-common-lib.asp"-->
<style type="text/css">
	.ui-datepicker table {
		border: 0;
	}
</style>
<script type="text/javascript">
	$(function() {
		//var $tr;
		//$("#fm_contact").validationEngine();
		$(".datepicker").datepicker();
		$("#bt_contact").click(function(){
			$("#fm_contact")[0].reset();
			$("#dv_contact").dialog("open");
		});
		$("#tb_contact a").live('click',function(e){
			e.preventDefault();	
			//$tr=$(this).parent().parent();
			$.getJSON("json_crm_contact.asp?action=get&contactid="+$(this).attr("href"),function(data){
				if(data.bStatus){
					$("#name").val(data.rData.name);
					$("#telephone").val(data.rData.telephone);
					$("#sex").val(data.rData.sex);
					$("#age").val(data.rData.age);
					$("#qq").val(data.rData.qq);
					$("#msn").val(data.rData.msn);
					$("#email").val(data.rData.email);
					$("#contact_memo").val(data.rData.memo);
					$("#companid").val(data.rData.companid);
					$("#contactid").val(data.rData.id);
					$("#dv_contact").dialog("open");
				}
			});
		
		});
		$("#bt_process").click(function(){
			$("#dv_process").dialog("open");
		});
		$("#dv_contact").dialog({
			autoOpen: false,
			minHeight:200,
			minWidth: 400,
			modal: true,
			buttons: {
				"保存": function() {
					if($("#fm_contact").validationEngine('validate')){
						$.post("json_crm_contact.asp?action=set&",$("#fm_contact").serialize(),function(data){
							if(data.bStatus){
								var sex=(data.rData.sex==1) ? "女" : "男";
								var tr="<tr>";
								tr+="<td><a href="+data.rData.id+">"+data.rData.name+"</a></td>";
								tr+="<td>"+data.rData.telephone+"</td>";
								tr+="<td>"+sex+"</td>";
								tr+="<td>"+data.rData.age+"</td>";
								tr+="<td>"+data.rData.qq+"</td>";
								tr+="<td>"+data.rData.msn+"</td>";
								tr+="<td>"+data.rData.email+"</td>";
								tr+="<td>"+data.rData.empename+"</td>";
								tr+="<td>"+data.rData.memo+"</td>";
								tr+="</tr>";
								//console.log($("#tb_contact tbody tr a").attr("href"));
								//console.log(data.rData.id);
								//console.log($("#tb_contact tbody tr a").attr("href")==data.rData.id);
								//$tr.remove();
								$("#tb_contact tbody a[href="+data.rData.id+"]").parent().parent().remove();
								$("#tb_contact tbody").prepend(tr);
								$("#dv_contact").dialog( "close" );
							}
						},"json");
					}
				},
				"取消": function() {
					$(this).dialog( "close" );
				}

			}
		});
		$("#dv_process").dialog({
			autoOpen: false,
			minHeight:200,
			modal: true,
			buttons: {
				"登录": function() {
					$.post("login.asp",{action:"登录",username:$("#login_username").val(),password:$("#login_password").val()},function(data){
						if(data.bStatus){
							if($("#url").val()){
								location.href=$("#url").val();
							}else{
								location.href="index.asp";
							}
						}else{
							alert(data.sInfo);
						}
					},"json");
				},
				"取消": function() {
					$(this).dialog( "close" );
				}

			}
		});
		
		
		$("#bt_over").click(function(e){
			if(!confirm("完成前请先保存当前处理的单子，确定已经保存过了？")){
				e.preventDefault();
			}
		});
		
		$("#visit").click(function(){
			if(!$(this).prop("checked")){
				$("#visit_address,#visit_startdate,#visit_enddate").val("").prop("disabled",true);
			}else{
				$("#visit_address,#visit_startdate,#visit_enddate").prop("disabled",false)
			}
		});
		$("#assist").click(function(){
			if(!$(this).prop("checked")){
				$("#assist_content").val("").prop("disabled",true);
			}else{
				$("#assist_content").prop("disabled",false)
			}
		});
		
	});
</script>
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
id=trim(SafeRequest("id",0))
submit=trim(SafeRequest("submit",0))
if submit<>"" then
	address=trim(SafeRequest("address",0))
	location=trim(SafeRequest("location",0))
	web=trim(SafeRequest("web",0))
	memo=trim(SafeRequest("memo",0))
	visit=trim(SafeRequest("visit",0))
	visit_address=trim(SafeRequest("visit_address",0))
	visit_startdate=trim(SafeRequest("visit_startdate",0))
	visit_enddate=trim(SafeRequest("visit_enddate",0))
	if visit="" then
		visit=0
		visit_address=""
		visit_startdate=""
		visit_enddate=""
	end if
	process_content=trim(SafeRequest("process_content",0))
	assist=trim(SafeRequest("assist",0))
	assist_content=trim(SafeRequest("assist_content",0))
	if assist="" then 
		assist=0
		assist_content=""
	end if
	success=trim(SafeRequest("success",0))
	if success="" then success=0
	touch=trim(SafeRequest("touch",0))
	post=trim(SafeRequest("post",0))
	crm_update=formattime(now(),"{Y}-{m}-{d} {h}:{n}:{s}")
	post_update=crm_update
	
	
	
	if submit="退回" then
		post=2
	end if
	if submit="接单" then
		post=3
	end if
	if submit="完成" then
		post=4
	end if
	if submit="保存" then
		sql="update crm set address='"&address&"',location='"&location&"',web='"&web&"',memo='"&memo&"',visit="&visit&",visit_address='"&visit_address&"',visit_startdate='"&visit_startdate&"',visit_enddate='"&visit_enddate&"',assist="&assist&",assist_content='"&assist_content&"',success="&success&",crm_update='"&crm_update&"',touch=1 where id="&id
		if process_content<>"" then
			sql_process="insert into crm_process(company,process_content,empe) values("&id&",'"&process_content&"',"&session("iId")&")"
			call ExecuteCommand(sql_process,false)
		end if
		' response.write sql
	end if
	if submit="退回" or submit="接单" or submit="完成" then
		sql="update crm set post="&post&",post_update='"&post_update&"',crm_update='"&crm_update&"' where id="&id
	end if
	
	
	call ExecuteCommand(sql,false)
end if
if id<>"" then
	sql = "select * from crm where id="&id
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.Open sql,conn,1,1
	if not rs.eof then
		company=rs("company")
		address=rs("address")
		location=rs("location")
		boxs=rs("boxs")
		cds=rs("cds")
		web=rs("web")
		target=rs("target")
		source=rs("source")
		change=rs("change")
		memo=rs("memo")
		visit=rs("visit")
		visit_address=rs("visit_address")
		visit_startdate=rs("visit_startdate")
		visit_enddate=rs("visit_enddate")
		' process_content=rs("process_content")
		assist=rs("assist")
		assist_content=rs("assist_content")
		success=rs("success")
		post=rs("post")
		touch=rs("touch")
	else
		'response.write("未找到数据")
		response.redirect("error.asp?id=1")
	end if
	rs.close
	set rs=nothing
end if
if not CheckPostFlag(session("aaPostFlag"),post,2) then call JumpErrorPage(2)
%>
<body>
<!--#include file="lib/header.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
	<div id="col3" role="main">
		<div id="col3_content" class="clearfix">
			<form id="form1" name="form1" method="post" class="yform" role="application">
				<fieldset>
					<legend><%=company%></legend>
					<div class="subcolumns">
						<div class="c50l columnar">
							<div class="type-text">
								<label for="address">客户地址*</label>
								<input name="address" id="address" type="text" class="validate[required]" value="<%=address%>" />
							</div>
							<div class="type-select">
								<label for="location">选择地点*</label>
								<select id="location" name="location">
									<%
										Set rs_location = Server.CreateObject("ADODB.Recordset")
										sql = "SELECT * FROM crm_location order by id"
										rs_location.Open sql,conn,1,1
										do while not rs_location.eof
									%>
									<option value="<%=rs_location("id")%>" <%if rs_location("id")=location then response.write("selected='selected'")%>><%=rs_location("location")%></option>
									<%
											rs_location.movenext
										loop
										rs_location.close
										set rs_location=nothing
									%>
								</select>
							</div>
							<div class="type-text">
								<label for="web">网址</label>
								<input class="validate[required]" name="web" id="web" type="text" value="<%=web%>" />
							</div>
							<div class="type-text">
								<label for="memo">备注</label>
								<textarea name="memo" id="memo"><%=memo%></textarea>
							</div>
						</div>
						<div class="c50r">
							<div class="type-text">
								<label>箱量：<%=boxs%> 单量：<%=cds%></label>
							</div>
							<div class="type-text">
								<label>主要方向：</label><%=target%>
							</div>
							<div class="type-text">
								<label>交易方式：</label><%=change%>
							</div>
							<div class="type-text">
								<label>主要工厂：</label><%=source%>
							</div>
						</div>
					</div>
					<table id="tb_contact" class="full">
						<thead>
							<tr>
								<th scope="col">姓名</th>
								<th scope="col">电话</th>
								<th scope="col">性别</th>
								<th scope="col">年龄</th>
								<th scope="col">QQ</th>
								<th scope="col">MSN</th>
								<th scope="col">Email</th>
								<th scope="col">添加人</th>
								<th scope="col">备注</th>
							</tr>
						</thead>
						<tbody>
							<%
								Set rs_contact = Server.CreateObject("ADODB.Recordset")
								sql = "SELECT crm_contact.*,crm_empe.empe as empename FROM crm_contact,crm_empe where crm_empe.id=crm_contact.empe and crm_contact.company="&id&" order by contact_update desc"
								rs_contact.Open sql,conn,1,1
								do while not rs_contact.eof
							%>
							<tr>
								<td><a href="<%=rs_contact("id")%>"><%=rs_contact("name")%></a></td>
								<td><%=rs_contact("telephone")%></td>
								<td><%if rs_contact("sex") then response.write("女") else response.write("男")%></td>
								<td><%=rs_contact("age")%></td>
								<td><%=rs_contact("qq")%></td>
								<td><%=rs_contact("msn")%></td>
								<td><%=rs_contact("email")%></td>
								<td><%=rs_contact("empename")%></td>
								<td><%=rs_contact("memo")%></td>
							</tr>
							<%
									rs_contact.movenext
								loop
								rs_contact.close
								set rs_contact=nothing
							%>
						</tbody>
					</table>
				</fieldset>
					<div class="subcolumns">
						<div class="c50l">
							<div class="subcl">
				<fieldset class="full">
					<legend>联系过程</legend>
							<div class="type-check">
								<input type="checkbox" name="visit" id="visit" value="1" <%if visit=1 then response.write("checked='checked'")%> />
								<label for="visit">计划拜访</label>
							</div>
							<div>
								出差地点
								<input type="text" name="visit_address" id="visit_address" value="<%=visit_address%>" <%if visit=0 then response.write("disabled='disabled'")%> />
								出差日期
								<input class="datepicker" type="text" size="10" name="visit_startdate" id="visit_startdate" value="<%=visit_startdate%>" readonly="readonly" <%if visit=0 then response.write("disabled='disabled'")%> />-<input class="datepicker" type="text" size="10" name="visit_enddate" id="visit_enddate" value="<%=visit_enddate%>" readonly="readonly" <%if visit=0 then response.write("disabled='disabled'")%> />
							</div>
							<div class="type-check">
								<input type="checkbox" name="assist" id="assist" value="1" <%if assist=1 then response.write("checked='checked'")%> />
								<label for="assist">需要协助</label>
							</div>
							<div class="type-text">
								<label for="assist_content">协助内容</label>
								<textarea name="assist_content" id="assist_content" <%if assist=0 then response.write("disabled='disabled'")%>><%=assist_content%></textarea>
							</div>
							<div class="type-check">
								<input type="checkbox" name="success" id="success" value="1" <%if success=1 then response.write("checked='checked'")%> />
								<label for="success">成功</label>
							</div>
				</fieldset>
							</div>
						</div>
						<div class="c50r full">
							<div class="subcr">
							<div class="type-text">
								<label for="process_content">联系内容</label>
								<textarea name="process_content" id="process_content"></textarea>
							</div>
							<table class="full">
								<thead>
									<tr><th colspan="3" scope="col">历史联系内容</th></tr>
								</thead>
								<tbody>
									<tr>
										<th scope="col">更新时间</th>
										<th scope="col">联系人</th>
										<th scope="col">联系内容</th>
									</tr>
									</tr>
									<%
										Set rs_process = Server.CreateObject("ADODB.Recordset")
										sql = "select process_update,process_content,crm_empe.empe as empename from crm_process left join crm_empe on crm_process.empe=crm_empe.id where company="&id&" order by process_update desc"
										rs_process.Open sql,conn,1,1
										do while not rs_process.eof
									%>
									<tr>
										<td><%=rs_process("process_update")%></td>
										<td><%=rs_process("empename")%></td>
										<td><%=rs_process("process_content")%></td>
									</tr>
									<%
											rs_process.movenext
										loop
										rs_process.close
										set rs_process=nothing
									%>
								</tbody>
							</table>
							</div>
						</div>
					</div>

				<div class="type-button">
					<input name="id" id="id" type="hidden" value="<%=id%>" />
					<input name="post" id="post" type="hidden" value="<%=post%>" />
					<%if post=2 then%>
					<input id="bt_accept" type="submit" name="submit" value="接单" />
					<%end if%>
					<%if post=3 then%>
					<input id="bt_back" type="submit" name="submit" value="退回" />
					<input id="bt_save" type="submit" name="submit" value="保存" />
					<input id="bt_over" type="submit" name="submit" value="完成" />
					<input id="bt_contact" type="button" value="添加联系人" />
					<%end if%>
				</div>
			</form>
			<table id="tb_dispatch" class="full">
				<thead>
					<tr><th colspan="3" scope="col">派单历史记录表</th></tr>
				</thead>
				<tbody>
					<tr>
						<th scope="col">派单时间</th>
						<th scope="col">派单人</th>
						<th scope="col">接单人</th>
					</tr>
					<%
						Set rs_dispatch = Server.CreateObject("ADODB.Recordset")
						sql = "select dispatch_update,d.empe as dispatcher,a.empe as accepter from crm_dispatch,crm_empe as d,crm_empe as a where crm_dispatch.dispatcher=d.id and crm_dispatch.accepter=a.id and company="&id&" order by dispatch_update desc"
						rs_dispatch.Open sql,conn,1,1
						do while not rs_dispatch.eof
					%>
					<tr>
						<td><%=rs_dispatch("dispatch_update")%></td>
						<td><%=rs_dispatch("dispatcher")%></td>
						<td><%=rs_dispatch("accepter")%></td>
					</tr>
					<%
							rs_dispatch.movenext
						loop
						rs_dispatch.close
						set rs_dispatch=nothing
					%>
				</tbody>
			</table>
					<div id="dv_contact" title="客户联系人">
				<form id="fm_contact" name="fm_contact" method="post" class="yform columnar" role="application">
					<div class="type-text">
						<label for="name">姓名*</label>
						<input name="name" id="name" type="text" class="validate[required,minSize[2]]" />
					</div>
					<div class="type-text">
						<label for="telephone">电话*</label>
						<input name="telephone" id="telephone" type="text" class="validate[required]" />
					</div>
					<div class="type-select">
						<label for="sex">性别*</label>
						<select name="sex" id="sex">
							<option value="0">男</option>
							<option value="1">女</option>
						</select>
					</div>
					<div class="type-text">
						<label for="age">年龄</label>
						<input name="age" id="age" type="text" maxlength="3" class="validate[custom[onlyNumber],minSize[2],maxSize[3]]" />
					</div>
					<div class="type-text">
						<label for="qq">QQ</label>
						<input name="qq" id="qq" type="text" />
					</div>
					<div class="type-text">
						<label for="msn">MSN</label>
						<input name="msn" id="msn" type="text" class="validate[custom[email]]" />
					</div>
					<div class="type-text">
						<label for="email">Email</label>
						<input name="email" id="email" type="text" class="validate[custom[email]]" />
					</div>
					<div class="type-text">
						<label for="contact_memo">备注</label>
						<textarea name="contact_memo" id="contact_memo"></textarea>
					</div>
					<input name="contactid" id="contactid" type="hidden" />
					<input name="companyid" id="companyid" type="hidden" value="<%=id%>" />
				</form>
			</div>

		</div>
	</div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<!--#include file="lib/connclose.asp"-->

